﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PhotoGalleryEnteties;
using PhotogalleryModel;
using photogalleryMVC.Models;

namespace photogalleryMVC.Controllers
{
    public class UsersController : PhotoGalleryController
    {
        //
        // GET: /Users/

        public ActionResult Index()
        {
            
            return View(UserRepository.GetAllUsers() );
        }

      
        public ActionResult Administrating()
        {
            
            return View();
        }


        
        [HttpPost ]
        public ActionResult UserList([FromJson]PagingData pagingData )
        {
            int totalPages;
            pagingData = pagingData ?? new PagingData() {CurrentPage = 1, ItemsOnPage = 5};
            ItemsPage<GalleryUser> users = UserRepository.GetUsersPage(pagingData.ItemsOnPage, pagingData.CurrentPage,
                                                                         out totalPages);
            IEnumerable<string> allowedRoles = UserRepository.GetAllowedRoles();

            return Json(new UserList (users ,totalPages ,pagingData.ItemsOnPage ,allowedRoles));
        }

        [Authorize(Roles = "admin")]
        [HttpPost ]
        public ActionResult EditUser()
        {
            return Json(null);
        }

        [Authorize(Roles = "admin")]
        public ActionResult DeleteUser()
        {
            return Json(null);
        }

    }
}
